package com.xh.demo.feign.fallback;

import com.xh.demo.commons.model.response.R;
import com.xh.demo.feign.ProductStockServiceFeign;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author wen
 * @apiNote OrderFeignFallback
 * @since 2021-12-11
 */
@Slf4j
@Component
public class ProductStockFeignFallback implements FallbackFactory<ProductStockServiceFeign> {

    @Override
    public ProductStockServiceFeign create(Throwable throwable) {
        log.info("【商品服务-库存接口调用失败】【{}】", throwable.getMessage());
        return new ProductStockServiceFeign() {

            @Override
            public R<Integer> detail(Long skuId) {
                return R.success(-1);
            }

            @Override
            public R<String> detailV2(Long id) {
                return R.failed("FAILED");
            }

            @Override
            public R<String> reStock(Long id) {
                return R.failed("re-stock-failed!!!");
            }
        };
    }

}
